package api

import (
	"github.com/kataras/iris/v12"
	"github.com/mlogclub/simple"

	"bbs-go/controllers/render"
	"bbs-go/services/cache"
)

type CategoryController struct {
	Ctx iris.Context
}

/**
 * showdoc
 * @catalog api/分类
 * @title 获取分类信息
 * @method get
 * @url /api/category/{id}
 * @param id 必选 int64 分类id
 */
func (this *CategoryController) GetBy(categoryId int64) *simple.JsonResult {
	category := cache.CategoryCache.Get(categoryId)
	if category == nil {
		return simple.JsonErrorMsg("分类不存在")
	}
	return simple.JsonData(render.BuildCategory(category))
}
